<template>
    <orh-table add="add" pages :pageDate="pageDate"
        @on-add="addSilde" @on-page-change="queryData"
        search :searchOption="typelist" :searchOptionSelected="searchOptionSelected" @on-search='searchfun'
        reload  @on-reload="refresh">
            <Table :columns="columns1" :loading="tableload" :data="datalist" slot="table"></Table>

            <orh-sidebar v-model="show" :title="pageTitle" scale slot="others">
                <component :is='"Operation"' :infoId='infoId' @showParent='showParent=>show=showParent' @backList='backList'></component>
            </orh-sidebar>
    </orh-table>
</template>
<script>
export default {
    components: {
        Operation: resolve => {require(['./Operation.vue'], resolve);},
    },
    name: "studentfilesmodule-studentstatuschanges",
    data () {
        return {
            searchOptionSelected: "student_name",
            typelist:[
                {
                    value: 'student_name' ,
                    label: '姓名',
                },
            ],
            listUrl:'api/student/v1/studentlearnstatus/changes_lists?page=',
            pageDate: {
                total: 0,
                current_page: 1,
                per_page: 10
            },

            // 列表接口请求携带参数
            condition:{
                searchvalue:'',
                searchtype:'student_name',
            },

            pageTitle:null,//右边页面的title
            tableload:true,//表格加载动画

            loading: true,

            show:false,

            which_to_show: "" ,//判断修改或添加组件显示与否
            datalist:[],//年级变量
            infoId: null,//用于向修改页面传id值
            columns1: [
                    {
                        title: '姓名',
                        render: (h, params) => {
                            let name = params.row.user.student_name.zh?params.row.user.student_name.zh : params.row.user.student_name.mn
                            return h('div', name);
                        }
                    },
                    {
                        title: '原班级',
                        render: (h, params) => {
                            if(params.row.original_eclass!=null){
                                let name = params.row.original_eclass.grade.grade_name.zh?params.row.original_eclass.grade.grade_name.zh:params.row.original_eclass.grade.grade_name.mn+' '+params.row.original_eclass.eclass_name.zh?params.row.original_eclass.eclass_name.zh:params.row.original_eclass.eclass_name.mn
                                return h('div', name);
                            }
                        }
                    },
                    {
                        title: '现班级',
                        render: (h, params) => {
                            if(params.row.go_eclass!=null){
                                let name = params.row.original_eclass.eclass_name.zh?params.row.original_eclass.eclass_name.zh:params.row.original_eclass.eclass_name.mn+' '+params.row.go_eclass.eclass_name.zh?params.row.go_eclass.eclass_name.zh:params.row.go_eclass.eclass_name.mn
                                return h('div', name);
                            }
                        }
                    },
                    {
                        title: '异动类型',
                        render: (h, params) => {
                            if(params.row.transaction_type){
                                let name = params.row.transaction_type.dictionary_name.zh?params.row.transaction_type.dictionary_name.zh:params.row.transaction_type.dictionary_name.mn
                                return h('div', name);
                            }
                        }
                    },
                    {
                        title: '异动原因',
                        render: (h, params) => {
                            let name = params.row.reason?params.row.reason.zh?params.row.reason.zh:params.row.reason.mn.zh?params.row.reason.zh:params.row.reason.mn:''
                                return h('div', name);

                        }
                    },
                    {
                        title: '异动时间',
                        key: 'eclass_time',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 80,
                        align: 'center',
                        render: (h, params) => {
                            // let dis=params.row.transaction_type.dictionary_id===360 ? true : false

                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                        // disabled:dis
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
                                            this.update(params.row.eclass_records_id)
                                        }
                                    }
                                }, '编辑')
                            ]);
                        }
                    }

                ],
            }
        },

        methods: {

            /************************************************************
             *
             * 请求列表数据
             *
             ************************************************************/
            queryData(index=1){
                this.tableload = true
                this.$http.get(`${this.listUrl}${index}`,{params:this.condition})
                .then(val=>{
                    this.datalist=val.data.data
                    if(val.data){
                        this.pageDate.total=val.data.total
                        this.pageDate.per_page=val.data.per_page
                        this.pageDate.current_page=val.data.current_page
                    }
                    this.tableload = false
                })
                .catch(err=>{
                    console.log(err);
                    if(err.code && err.code==422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload = false;
                })
            },

            /************************************************************
             *
             * 点击添加
             *
             ************************************************************/
            addSilde () {
                this.show=true
                this.infoId = false
                this.pageTitle='添加'
            },

            /************************************************************
             *
             * 点击编辑
             *
             ************************************************************/
            update(index){
                this.infoId = index
                this.show=true
                this.pageTitle='修改'
            },

            /************************************************************
             *
             * 修改添加返回数据更新
             *
             ************************************************************/
            backList(val){
                if(val == true){
                    this.show=false
                    this.queryData(this.pageDate.current_page);
                }
            },

            /************************************************************
             *
             * 刷新数据（当前分页）
             *
             ************************************************************/
            refresh(){
                this.queryData(this.pageDate.current_page)
            },


            /************************************************************
             *
             * 关键字搜索请求列表数据
             *
             ************************************************************/
            searchfun(val,type){
                this.condition.searchtype=type
                this.condition.searchvalue=val
                this.listUrl='api/student/v1/studentlearnstatus/changes_lists?page='
                this.queryData()
            },
        },
        mounted(){
            this.queryData();
        },
}
</script>
